## poly.asm
## 
## Program to calculate 2x^4 + 7x^3 - 15x^2 + 3x + 2
##
## Register Use:
##  $1    base register address
##  $2    x
##  $3    accumulator

        .text
        .globl  main

main: 
        lui   $1,0x1000     #Init base register
        lw    $2,0($1)      #Load x
        ori   $3,$0,2       #Loads 2 into the accumulator
        mult  $3,$2         #Multiplies 2x
        mflo  $3            #Loads 2x into the accumulator
        addu  $3,$3,7       #Loads 2x+7 into the accumulator
        sll   $0,$0,0       #No-op
        mult  $3,$2         #Multiples (2x+7) * x
        mflo  $3            #Loads 2x^2+7x into the accumlator
        addu  $3,$3,-15     #Loads 2x^2+7x-15 into the accumulator
        sll   $0,$0,0       #No-op
        mult  $3,$2         #Multiplies (2x^2+7x-15) * x
        mflo  $3            #Loads 2x^3+7x^2-15x into the accumulator
        addu  $3,$3,3       #Loads 2x^3+7x^2-15x+3 into the accumulator
        sll   $0,$0,0       #No-op
        mult  $3,$2         #Multiplies (2x^3+7x^2-15x+3) * x
        mflo  $3            #Loads 2x^4+7x^3-15x^2+3x into the accumulator
        addu  $3,$3,2       #Loads 2x^4+7x^3-15x^2+3x+2 into the accumulator
        sw    $3,4($1)      #Stores answer into memory


        .data
x:      .word   3           #Value of x

## End of file
